$(function(){
	var screenH=window.screen.height;
	var layout=$('#layout');
	layout.height(screenH);
	localStorage.clear();
})
//密码的显示与隐藏
$(function(){
	var $selector = $('#switch');
	$selector.off('tap').on('tap',function(){
		var $this=$(this);
		$this.hasClass('bg-hide')?$this.addClass('bg-show').removeClass('bg-hide').prev('input').attr({'type':'text'}):$this.addClass('bg-hide').removeClass('bg-show').prev('input').attr({'type':'password'})
	})
	
})

$(function(){
	var tabLogin = $('#layout header').find('p');
	var passWord = $('#main').find('.gma-pas');
	var getCode = $('#getCode');
	//普通登录和快捷登录
	tabLogin.off('tap').on('tap',function(){
		var $this=$(this);
		var index = $this.index();
		index===0?$this.addClass('gma-loginTab').siblings().removeClass('gma-loginTab')&&passWord.eq(index).show().siblings().hide()&&getCode.hide():$this.addClass('gma-loginTab').siblings().removeClass('gma-loginTab')&&passWord.eq(index).show().siblings().hide()&&getCode.show();
	});
	var sendData={};
	var globalHost=common.globalHost;
	var loginPort=common.loginPort;
	var url=globalHost+loginPort;
	var resultGetTestCode=baseInfoForm.getTestCode({targetSelector:baseInfoForm.getCode});
	baseInfoForm.submit.off('tap').on('tap',function(e){
		var $this=$(this);
	    var checkCase=$this.hasClass("act-ago");
	    	sendData=common.getSendDataByForm(baseInfoForm.form);
	  	var checkLogin = tabLogin.eq(0);
	        if(checkLogin.hasClass('gma-loginTab')){
	        	//普通登录
	    		var resultPassword=baseInfoForm.testPassword({targetSelector:baseInfoForm.password,noticeMsg:"密码"});
	    		var resultTel=baseInfoForm.regTestTel({targetSelector:baseInfoForm.tel,noticeMsg:"手机号",length:11});
	        	//删除验证码的传输数据
	        	delete sendData['smsCode'];
	        	if(!!checkCase&&!!resultPassword&&!!resultTel){
	        		callAjax(url,sendData);
	        	}else{
	        		console.log("不准发送ajax请求");
	        	}
	        	e.preventDefault();
	        	return false;
	        }else{
	        	//快速登录
	    		var resultTestCode=baseInfoForm.testMobileCode({targetSelector:baseInfoForm.testCode,noticeMsg:"请输入验证码"});
	    		var resultTel=baseInfoForm.regTestTel({targetSelector:baseInfoForm.tel,noticeMsg:"手机号",length:11});
	        	delete sendData['pw'];
	        	if(!!checkCase&&!!resultTel&&!!resultTestCode){
	        		callAjax(url,sendData);
	        	}else{
	        		console.log("不准发送ajax请求");
	        	}
	        	e.preventDefault();
	        	return false;
	        }
	});	
});
function actedStyle () {
    baseInfoForm.submit.removeClass("act-ago").addClass("acted-yet");
}
function actAgoStyle () {
    baseInfoForm.submit.removeClass("acted-yet").addClass("act-ago");
}
function callAjax(url,sendData){
	baseInfoForm.formPost({
		url:url,
		sendData:sendData,
		resSuccess:function(data){
			var data=data['res']['data'];
			actedStyle();
			baseInfoForm.form[0].reset();
			common.setLocalStorage('H5-agentInfo',JSON.stringify(data));
			window.location.href="index.html";
		},
		resFailed:function(data){
			actAgoStyle();
		}
	});
}